package chapter03

import org.apache.spark.{SparkConf, SparkContext}

object Test11_GroupBy {
  def main(args: Array[String]): Unit = {
    val pay = new SparkConf().setMaster("local[*]").setAppName("group")
    val sc = new SparkContext(pay)
    val value = sc.makeRDD(List(1, 2, 3, 4, 5, 6))
    println(value.groupBy(e=>e%2).collect().toList)
    //练习 wordCount
    val value1 = sc.textFile("input/word.txt")
    println(value1.flatMap(e => e.split(" ").toList)
      .groupBy(e=>e)
      .map(e=>(e._1,e._2.size))
      .collect().mkString("Array(", ", ", ")"))
  }
}
